<?php

namespace app\adminapi\controller\system;

use app\adminapi\service\SysNoticeService;
use app\adminapi\validate\SysNoticeValidate;
use app\common\controller\BaseAdminController;

class SysNoticeController extends BaseAdminController
{
    public array $notNeedLogin = [];

    public function list()
    {
        $params = (new SysNoticeValidate())->get()->goCheck('list');
        $list = (new SysNoticeService())->list($params);
        return app('json')->successWithData($list);
    }

    /**
     * @title   新增公告
     * @businessType    INSERT
     */
    public function insert()
    {
        $params = (new SysNoticeValidate())->post()->goCheck('insert');
        (new SysNoticeService())->addSysNotice($params);
        return app('json')->success();
    }

    /**
     * @title   删除公告
     * @businessType    DELETE
     */
    public function delete()
    {
        $params = (new SysNoticeValidate())->delete()->goCheck('delete');
        $result = (new SysNoticeService())->deleteSysNotice($params['noticeId']);
        return app('json')->successWithData($result);
    }

    public function query()
    {
        $params = (new SysNoticeValidate())->get()->goCheck('query');
        $result = (new SysNoticeService())->getSysNotice($params['noticeId']);
        return app('json')->successWithData($result);
    }

    /**
     * @title   更新公告
     * @businessType    UPDATE
     */
    public function update()
    {
        $params = (new SysNoticeValidate())->put()->goCheck('update');
        $result = (new SysNoticeService())->updateSysNotice($params);
        return app('json')->successWithData($result);
    }
}